package com.dianyingyuyue.service;
import com.dianyingyuyue.entity.Plan;
import com.dianyingyuyue.util.JdbcUtil;

import java.util.List;

public class PlanService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into plan(pname,pjianjie,pdaoyan,pzhujiao,pshichang,paddress,pdate,ctime) values(?,?,?,?,?,?,?,now()) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<Plan> getListAll(int page, int rows, Plan obj) {
        String sql="select * from plan where 1=1 ";
        if(obj.getPname()!=null&&!obj.getPname().equals("")){
            sql+=" and pname like '%"+obj.getPname()+"%' ";
        }
        sql+=" limit "+page+","+rows;
        List<Plan> dblist= JdbcUtil.executeQuery(sql,null,Plan.class);
        return dblist;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(Plan obj) {
        String sql="select * from plan where 1=1 ";
        if(obj.getPname()!=null&&!obj.getPname().equals("")){
            sql+=" and pname like '%"+obj.getPname()+"%' ";
        }
        List<Plan> memberList= JdbcUtil.executeQuery(sql,null,Plan.class);
        return memberList.size();
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update plan set pname=?,pjianjie=?,pdaoyan=?,pzhujiao=?,pshichang=?,paddress=?,pdate=?,utime=now() where id=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param id
     * @return
     */
    public Plan getId(String id) {
        String sql="select * from plan where id="+id;
        List<Plan> users= JdbcUtil.executeQuery(sql,null,Plan.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from plan  where id=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
